//
// Created by yanhai on 2021/11/9.
//

#include <iostream>
#include <thread>
#include <mutex>
#include <utility/util/spinlock.h>

using namespace std;

int num = 0;
spinlock s;

void worker_thread(const char *name)
{
    int count = 10;
    while (count--) {
        lock_guard<spinlock> lock(s);
        num++;
        cout << name << ": " << num << endl;
        this_thread::sleep_for(chrono::seconds(3));
    }
}

int main()
{
    thread t1(worker_thread, "t1");
    thread t2(worker_thread, "t2");
    thread t3(worker_thread, "t3");

    t1.join();
    t2.join();
    t3.join();

    return 0;
}
